"""
@author: Sergiy Tsymbalyuk
"""

from pylons import request, session

from chowa.lib.base import render
from chowa.lib.site.layout import PanelComponent


class AuthForm(object):
    __metaclass__ = PanelComponent
    
    def __init__(self, options={}):
        pass
    
    def render(self):
        identity = request.environ.get('repoze.who.identity')
        if not identity:
            return render('/auth/login_form.html')
        user = identity['user']
        session['user_id'] = user.id
        session.save()
        if user.person:
            username = '%s %s' % (user.person.surname, user.person.name)
        else:
            username = user.username
        return render('/auth/logout_form.html', extra_vars={'username':username})
